package org.dtrd.modules.control.entity.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveLaboratory;
import org.dtrd.modules.control.entity.po.DtrdEntRdSigninTargetDetail;
import org.dtrd.modules.record.entity.po.*;

import java.util.List;

/**
 * @author qr
 * @date 2022/1/11 10:38
 */
@ApiModel("患者首页控制目标数据")
@Getter
@Setter
public class PatientTargetValue {

    @ApiModelProperty("体质指数（BMI）")
    private Float bmi;

    @ApiModelProperty("糖化血红蛋白（HbA1c")
    private Float hbA1c;

    @ApiModelProperty("空腹血糖（FBG）")
    private Float fbg;

    @ApiModelProperty("餐后血糖（PBG）")
    private Float pbg;

    @ApiModelProperty("舒张压/低压")
    private Float pressureLow;

    @ApiModelProperty("收缩压/高压")
    private Float pressureHigh;

    @ApiModelProperty("总胆固醇（TC）")
    private Float tc;

    @ApiModelProperty("甘油三酯（TG）")
    private Float tg;

    @ApiModelProperty("高密度脂蛋白（HDL）")
    private Float hdl;

    @ApiModelProperty("低密度脂蛋白（LDL）")
    private Float ldl;

    @ApiModelProperty("腰围")
    private Float waistLine;

    @ApiModelProperty("心率")
    private Float heartRate;

    @ApiModelProperty("体重")
    private Float weight;

    @ApiModelProperty("用药")
    private String drug;

    @JsonIgnore
    private Integer count = 0;

    public PatientTargetValue setLabValue(DtrdEntRdArchiveLaboratory po) {
        hbA1c = po.getHba1c();
        tc = po.getTc();
        tg = po.getTg();
        hdl = po.getHdlc();
        ldl = po.getLdlc();
        count++;
        return this;
    }

    public PatientTargetValue setWaistLineValue(DtrdEntRdSigninWaistline po) {
        waistLine = Float.valueOf(po.getWaistlineValue());
        count++;
        return this;
    }

    public PatientTargetValue setDrug(DtrdEntRdSigninMedicalRecord medicalRecord) {
        drug = medicalRecord.getMedicalRecordDescribe();
        count++;
        return this;
    }

    public PatientTargetValue setBloodValueAndHeartRate(DtrdEntRdSigninBloodPressure po) {
        pressureLow = Float.valueOf(po.getBloodPressureLowVoltage());
        pressureHigh = Float.valueOf(po.getBloodPressureHighPressure());
        heartRate = Float.valueOf(po.getBloodPressureHeartRate());
        count++;
        return this;
    }

    public PatientTargetValue setSugarValueLimosis(DtrdEntRdSigninSugarValue sugarValue) {
        fbg = sugarValue.getSugarValueSugarValue();
        count++;
        return this;
    }

    public PatientTargetValue setSugarValueAfterMeal(DtrdEntRdSigninSugarValue sugarValue) {
        fbg = sugarValue.getSugarValueSugarValue();
        count++;
        return this;
    }

    public PatientTargetValue setWeightAndBmi(DtrdEntRdSigninHeightWeight heightWeight) {
        bmi = heightWeight.getHeightWeightBmi();
        weight = heightWeight.getHeightWeightWeight();
        count++;
        return this;
    }

    public PatientTargetValue parseFromPo(List<DtrdEntRdSigninTargetDetail> poList){
        for (DtrdEntRdSigninTargetDetail detail : poList) {
            Constant.TargetProject targetDetail = Constant.TargetProject.valueOf(detail.getProjectType());
            assert targetDetail != null;
            switch (targetDetail) {
                case BMI:
                    bmi = detail.getTargetLow();
                    break;
                case TC:
                    tc = detail.getTargetLow();
                    break;
                case TG:
                    tg = detail.getTargetLow();
                    break;
                case FBG:
                    fbg = detail.getTargetLow();
                    break;
                case PBG:
                    pbg = detail.getTargetLow();
                    break;
                case LDL:
                    ldl = detail.getTargetLow();
                    break;
                case HDL:
                    hdl = detail.getTargetLow();
                    break;
                case WAIST:
                    waistLine = detail.getTargetLow();
                    break;
                case HEART_RATE:
                    heartRate = detail.getTargetLow();
                    break;
                case PRESSURE_LOW:
                    pressureLow = detail.getTargetLow();
                    break;
                case PRESSURE_HIGH:
                    pressureHigh = detail.getTargetLow();
                    break;
                case HBA1C:
                    hbA1c = detail.getTargetLow();
                    break;
                case WEIGHT:
                    weight = detail.getTargetLow();
                    break;
                case DRUG:
                    drug = detail.getRemark();
                default:
                    break;
            }
        }
        return this;
    }
}
